<%-- 
    Document   : edit
    Created on : Apr 6, 2011, 9:44:05 AM
    Author     : Noi Nho
--%>

<%@page import="dto.TourCategory"%>
<%@page import="dao.TourCateDAO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="dto.Tour"%>
<%@page import="dao.TourDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<c:if test="${param['tourID']=='' || param['tourID']==null}">
    <jsp:forward page="administrator.jsp?page=tour" />
</c:if>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Edit Tour</title>
    </head>
    <body>
        <a href="administrator.jsp?page=tour">Tour Management</a>
        <br>
        <form action="AdminAction?page=tour&action=edit&tourID=${param['tourID']}" name="tourEdit" method="post">
            <%
                        TourDAO tourDAO = new TourDAO();
                        Tour tour = tourDAO.getTour(Integer.parseInt(request.getParameter("tourID").toString()));
                        if (tour != null) {
                            request.setAttribute("tour", tour);

            %>
            Tour ID: <% out.println(tour.getTourID());%>
            <br>
            <select name="category">
                <option value="">-- Chose tour category --</option>
                <%
                                        ArrayList<TourCategory> tourCates = new ArrayList<TourCategory>();
                                        TourCateDAO tourCateDAO = new TourCateDAO();
                                        tourCates = tourCateDAO.getAllTourCate();
                                        if (tourCates != null) {
                                            for (TourCategory item : tourCates) {
                                                if (item.getTourCateID() == tour.getTourCate().getTourCateID()) {
                %>

                <option selected="true" value="<% out.println(item.getTourCateID());%>"><% out.println(item.getCateName());%></option>
                <%
                                                 } else {
                %>
                <option value="<% out.println(item.getTourCateID());%>"><% out.println(item.getCateName());%></option>
                <%
                                                }
                                            }
                                        }
                %>
            </select>
            <br>
            Tour Name: <input type="Text" name="tourName" value="<% out.println(tour.getName());%>">
            <br>
            Price: <input type="Text" name="price" value="<% out.println(tour.getPrice());%>">
            <br>
            Description: <input type="Text" name="description" value="<% out.println(tour.getDescription());%>">
            <br>
            <input type="submit" name="submit" value="Ok">
            <input type="reset" name="reset" value="reset">
            <%
                        }
            %>
        </form>

    </body>
</html>
